package py.com.sole.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author bala
 */
@Entity
@Table(name = "personas")
@XmlRootElement
@NamedQueries({
	@NamedQuery(name = "Persona.findAll", query = "SELECT p FROM Persona p"),
	@NamedQuery(name = "Persona.findById", query = "SELECT p FROM Persona p WHERE p.id = :id"),
	@NamedQuery(name = "Persona.findByNombre", query = "SELECT p FROM Persona p WHERE p.nombre = :nombre"),
	@NamedQuery(name = "Persona.findByApellido", query = "SELECT p FROM Persona p WHERE p.apellido = :apellido"),
	@NamedQuery(name = "Persona.findByEmail", query = "SELECT p FROM Persona p WHERE p.email = :email"),
	@NamedQuery(name = "Persona.findByDocumento", query = "SELECT p FROM Persona p WHERE p.documento = :documento"),
	@NamedQuery(name = "Persona.findBySexo", query = "SELECT p FROM Persona p WHERE p.sexo = :sexo"),
	@NamedQuery(name = "Persona.findByFechaNac", query = "SELECT p FROM Persona p WHERE p.fechaNac = :fechaNac"),
	@NamedQuery(name = "Persona.findByTelefono", query = "SELECT p FROM Persona p WHERE p.telefono = :telefono")})
public class Persona implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(nullable = false)
    private Integer id;
    @Basic(optional = false)
    @Column(nullable = false, length = 45)
    private String nombre;
    @Basic(optional = false)
    @Column(nullable = false, length = 45)
    private String apellido;
    @Column(length = 45)
    private String email;
    @Column(length = 100)
    private String documento;
    private Character sexo;
    @Column(name = "fecha_nac")
    @Temporal(TemporalType.DATE)
    private Date fechaNac;
    @Column(length = 2147483647)
    private String telefono;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "persona")
    private List<Padre> padreList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "persona")
    private List<Alumno> alumnoList;
    @JoinColumn(name = "tipo_documento_id", referencedColumnName = "id")
    @ManyToOne
    private TipoDocumento tipoDocumentoId;
    @JoinColumn(name = "direccion", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false, cascade=CascadeType.PERSIST)
    private Direccion direccion;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "persona")
    private List<Profesor> profesorList;

	public Persona() {
	}

	public Persona(Integer id) {
		this.id = id;
	}

	public Persona(Integer id, String nombre, String apellido) {
		this.id = id;
		this.nombre = nombre;
		this.apellido = apellido;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNombre() {
		return nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public String getApellido() {
		return apellido;
	}

	public void setApellido(String apellido) {
		this.apellido = apellido;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getDocumento() {
		return documento;
	}

	public void setDocumento(String documento) {
		this.documento = documento;
	}

	public Character getSexo() {
		return sexo;
	}

	public void setSexo(Character sexo) {
		this.sexo = sexo;
	}

	public Date getFechaNac() {
		return fechaNac;
	}

	public void setFechaNac(Date fechaNac) {
		this.fechaNac = fechaNac;
	}

	public String getTelefono() {
		return telefono;
	}

	public void setTelefono(String telefono) {
		this.telefono = telefono;
	}

	@XmlTransient
	public List<Padre> getPadreList() {
		return padreList;
	}

	public void setPadreList(List<Padre> padreList) {
		this.padreList = padreList;
	}

	@XmlTransient
	public List<Alumno> getAlumnoList() {
		return alumnoList;
	}

	public void setAlumnoList(List<Alumno> alumnoList) {
		this.alumnoList = alumnoList;
	}

	public TipoDocumento getTipoDocumentoId() {
		return tipoDocumentoId;
	}

	public void setTipoDocumentoId(TipoDocumento tipoDocumentoId) {
		this.tipoDocumentoId = tipoDocumentoId;
	}

	public Direccion getDireccion() {
		return direccion;
	}

	public void setDireccion(Direccion direccion) {
		this.direccion = direccion;
	}

	@XmlTransient
	public List<Profesor> getProfesorList() {
		return profesorList;
	}

	public void setProfesorList(List<Profesor> profesorList) {
		this.profesorList = profesorList;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof Persona)) {
			return false;
		}
		Persona other = (Persona) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "py.com.sole.model.Persona[ id=" + id + " ]";
	}

	public void setSexo(String sexo2) {
		// TODO Auto-generated method stub
		sexo = sexo2.charAt(0);
	}

	public void setDireccion(String direccion2) {
		// TODO Auto-generated method stub
		this.direccion.getDescripcion().equalsIgnoreCase(direccion2);
	}



}